package tests;

/**
 * Testing class for the DataStorage.java
 * @author joshuacw
 * 
 */

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import darksideoftheloom.*;

public class DataStorageTest {

	
	@Test
	public void test(){
		DataStorage ds = new DataStorage();
		
		List<Attendee> attends = attendeeTestData();
		
		Organizer org = organizerTestData();
		
		ds.save(attends, org);
		
		//assertEquals(organizerTestData(), ds.getOrganizer());
		org = ds.getOrganizer();
		System.out.println("org userID   = " + org.getUserID());
		System.out.println("    password = " + org.getPassword());
		System.out.println("organizer tested: thirsty village");
		
		//assertEquals(attendeeTestData(), ds.getAttendees());
		attends = ds.getAttendees();
				
		for(Attendee a: attends){
			System.out.println("user:" + a.getUsername() + " in output");
			System.out.println("password: " + a.getPassword());
			System.out.println("address: " + a.getAddress());
			System.out.println("email: " + a.getEmail());
			System.out.println("name: " + a.getName());
			if(a.getName().equalsIgnoreCase("Jill")){
				for(Submission s: a.getSubmissions()){
					if(s != null){
						WeavingDraft draft = s.getWeavingDraft();
						boolean[][] tie_up = draft.getTieUp();
						System.out.println("\n\nTIE_UP\n");
						for(int row = 0; row < tie_up.length; row++){
							System.out.print("{");
							for(int column = 0; column < tie_up[row].length; column++){
								System.out.print(tie_up[row][column] + ", ");
							}
							System.out.println("}");
						}
						
						boolean[][] threading = draft.getThreading();
						System.out.println("\n\nTHREADING\n");
						for(int row = 0; row < threading.length; row++){
							System.out.print("{");
							for(int column = 0; column < threading[row].length; column++){
								System.out.print(threading[row][column] + ", ");
							}
							System.out.println("}");
						}
						
						boolean[][] treadling = draft.getTreadling();
						System.out.println("\n\nTREADLING\n");
						for(int row = 0; row < treadling.length; row++){
							System.out.print("{");
							for(int column = 0; column < treadling[row].length; column++){
								System.out.print(treadling[row][column] + ", ");
							}
							System.out.println("}");
						}
					}
				}
			}
		}
	}
	
	private List<Attendee> attendeeTestData(){
		List<Attendee> list = new ArrayList<Attendee>();

		Attendee jill = new Attendee("Jill", "666-555-123-4567", "123 My st. NewAthens, Olypic Distric, Mars",
				   "mailJill@mars.colony1.fake", "un_jill", "PWyoucantguessme");
		WeavingDraft draft = new WeavingDraft(5,5,5,5);
		draft.changeThreading(0, 1, true);
		draft.changeTieUp(2, 1, true);
		draft.changeTreadling(2, 3, true);
		Submission a_submission = new Submission(jill.getName(), "jills_first_design",
                "A New Category", draft);
		
		jill.submit(a_submission);
		list.add(jill);
		
		list.add(new Attendee("Jake", "666-555-123-4568", "124 My st. NewAthens, Olypic Distric, Mars",
				   "mailJack@mars.colony1.fake", "un_jake", "youcantguessmyPW"));
		list.add(new Judge("Hill", "666-555-123-4569", "125 My st. NewAthens, Olypic Distric, Mars",
				   "mailHill@mars.colony1.fake", "un_hill", "jackandjillwentupthehill", "fetch-water"));
		
		return list;
	}
	
	private Organizer organizerTestData(){
		Organizer org = new Organizer("thirsty village", "fakepassword");
		
		return org;
	}
}
